﻿using Product_1_1.ServiceReference1;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Product_1_1.ViewModels
{
  public class Product_1_1_ViewModel : ReactiveUI.ReactiveObject
    {
        ServiceReference1.Container context = new ServiceReference1.Container(new Uri("http://localhost:1179/odata"));
        
        string quantity;
        public string Quantity
        {
            get
            {
                return quantity;
            }
            set  //DependencyProperty coding
            {
                this.RaiseAndSetIfChanged(ref quantity, value);
            }
        }

        IQueryable<Vita500> region1;
        public IQueryable<Vita500> Region1
        {
            get
            {
                return region1;
            }
            set  //DependencyProperty coding
            {
                this.RaiseAndSetIfChanged(ref region1, value);
            }
        }

        public ReactiveCommand<object> Initialize { get; private set; }

        public Product_1_1_ViewModel()
        {
            Initialize = ReactiveCommand.Create(
            this.WhenAny(vm => vm.Region1, str => true)
            );
            Initialize.Subscribe(_ =>
            {
                Quantity = "500";
                Region1 = (IQueryable<Vita500>)
                                from kkk in context.Vita500
                                select kkk;
                                 //new
                                 //{
                                 //    Vita_Id = kkk.Vita_Id,
                                 //    Vita_Unit = kkk.Vita_Unit,
                                 //    ProductDB = kkk.ProductDB,
                                 //    Pro_Id = kkk.Pro_Id,
                                 //    Vita_Name = kkk.Vita_Name,
                                 //    Vita_Quantity = kkk.Vita_Quantity,//*(Convert.ToInt32(Quantity))
                                 //               };
             //   context.Vita500.Select(kkk=> kkk == new Vita500 { Vita_Name = kkk.Vita_Name, Vita_Quantity= (kkk.Vita_Quantity*(Convert.ToInt32(Quantity))) });
            });
        }

        public event EventHandler Result = delegate { };
    }
}